var e = require('../@babel/runtime/helpers/objectSpread2.js'),
  r = require('../@babel/runtime/helpers/createForOfIteratorHelper.js'),
  o = require('1E1DDD9770B67DCF787BB59075001B27.js').systemType,
  t = 0;
module.exports = function () {
  var a = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
  try {
    var n = wx.getStorageSync('accessToken'),
      c = wx.getStorageSync('user');
    if (!n || !c)
      return console.log('没有token或者没有用户信息'), Promise.reject();
    var i = wx.getStorageSync('initSystem');
    if (!i) return console.log('没有初始化'), Promise.reject();
    if (1 != +i.stat2_is_open)
      return console.log('没有打开统计'), Promise.reject();
    if (!a || 0 === Object.keys(a).length)
      return void console.log('没有传入params,无法统计');
    var s = a.goodsIdArr,
      l = a.actionType;
    if (!s || 0 === s.length)
      return void console.log('没有传入goodsIdArr,无法统计');
    if (!l) return void console.log('没有传入actionType,无法统计');
    var g,
      y = wx.getStorageSync('DataReportArr') || [],
      f = 1,
      u = {
        entry_type: f ? +f : 1,
        credit_open_qty: 0,
        goods_id: 0,
        exposure_qty: 0,
        detail_qty: 0,
        share_qty: 0,
        confirm_qty: 0,
        cash_qty: 0,
        pay_qty: 0,
        cancel_qty: 0,
      },
      d = s,
      p = r(d);
    try {
      var v = function () {
        var o = g.value;
        if (
          0 === y.length ||
          (y &&
            !y.some(function (e) {
              return +e.goods_id == +o;
            }))
        ) {
          var t = u;
          for (var a in t)
            if (a === l) {
              t[a] = ++t[a];
              break;
            }
          y.push(e(e({}, t), {}, { goods_id: +o }));
        } else {
          var n,
            c = r(y);
          try {
            for (c.s(); !(n = c.n()).done; ) {
              var i = n.value;
              if (+i.goods_id == +o) {
                for (var s in i)
                  if (s === l) {
                    i[s] = ++i[s];
                    break;
                  }
                break;
              }
            }
          } catch (e) {
            c.e(e);
          } finally {
            c.f();
          }
        }
      };
      for (p.s(); !(g = p.n()).done; ) v();
    } catch (e) {
      p.e(e);
    } finally {
      p.f();
    }
    wx.setStorageSync('DataReportArr', y);
    var S = function () {
      if (wx.getStorageSync('DataReportArr')) {
        var e = JSON.stringify(wx.getStorageSync('DataReportArr')),
          r = { systemType: o, platform_type: o, stat: e };
        wx.removeStorageSync('DataReportArr'),
          wx.request({
            url: ''.concat(i.stat2_domain_name, '/v1/stat-goods/report'),
            data: r,
            header: {
              Authorization: 'Bearer '.concat(wx.getStorageSync('accessToken')),
            },
            method: 'post',
            timeout: 1e3,
            success: function (e) {
              0 != +e.data.code
                ? console.log('统计失败')
                : console.log('统计成功');
            },
            fail: function (e) {
              console.log('统计失败 fail');
            },
          });
      } else console.log('localStorage中无DataReportArr数据, 不执行上报, 退出');
    };
    if (y && y.length >= 5) return void S();
    !t &&
      (t = setTimeout(function () {
        clearTimeout(t), (t = 0), S();
      }, 18e4));
  } catch (e) {
    console.log(e);
  }
};
